﻿using CSharp;
using System;
using System.Collections.Generic;
using System.Text;

namespace CSharp
{
    public class MimicStack<T>
    {
        private T[] arrays;
        private int top = 0;
        public MimicStack(int length)
        {
            arrays = new T[length];
        }
        public void Push(T element)//截断式编程
        {
            if (top > arrays.Length)
            {
                Console.WriteLine("stack overflow");
            }
            else
            {
                arrays[top] = element;//元素放进栈顶指针指向的位置
                top++;
            }
        }
        public void Push(params T[] elements)//重载
        {
            for (int i = 0; i < elements.Length; i++)
            {
                Push(elements[i]);
            }
        }
        public void Pop(out bool succeed)
        {
            if (top == 0)
            {
                succeed = false;
                Console.WriteLine("The stack is empty");
            }
            else
            {
                top--;
                succeed = true;
                Console.WriteLine(arrays[top]);

            }
        }
        public bool Pop()
        {
            if (top == 0)
            {
                Console.WriteLine("The stack is empty");
                return false;
            }
            else
            {
                top--;
                Console.WriteLine(arrays[top]);
                return true;
            }

        }


    }
}
